package com.cneport.das.common.model.trans;

import com.cneport.das.common.utils.JsonUtil;
import com.cneport.das.common.validate.FieldCheck;
import com.cneport.das.common.validate.FvEnum;
import com.cneport.das.common.validate.Regexs;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.xml.bind.annotation.*;
import java.util.Arrays;

/**
 * @Desc ERP请求的报文对象
 * @Ver 1.0
 * @Author GavinZhang
 * @Company 东方物通科技有限（北京）公司
 * @Date 2021-12-20 14:35:23
 */
@Data
@XmlRootElement(name = "ErpPutRequest")
@XmlAccessorType(XmlAccessType.FIELD)
public class ErpPutRequest {
    @XmlElement(name = "reqHead")
    private ReqHead reqHead;
    @XmlElement(name = "reqData")
    private ReqData reqData;
    @XmlElement(name = "addInfos")
    private AddInfos addInfos;

    @XmlType
    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class ReqHead {
        @FieldCheck(name = "全局ID", type = FvEnum.STRING, isNullable = false, length = 32)
        private String guid;
        private String msgType;
        @FieldCheck(name = "内部编号", type = FvEnum.STRING, isNullable = false)
        private String copMsgId;
        @FieldCheck(name = "请求时间", type = FvEnum.DATE_STR, isNullable = false, regex = Regexs.C14)
        private String reqTime;
        private String senderId;
        private ReceiverIds receiverIds;
        @FieldCheck(name = "公司编号", type = FvEnum.STRING, isNullable = false)
        private String copNo;
    }

    @XmlType
    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class ReqData {
        private String data;
        private String trans;
    }

    public static void main(String[] args) {
        ErpPutRequest erpPutRequest = new ErpPutRequest();
        erpPutRequest.setReqHead(ReqHead.builder().guid("11111111222222221111111122222222").reqTime("20211230113029").msgType("CEB5233").copMsgId("132435423345").senderId("sender-1").copNo("vkyhOxYl").receiverIds(ReceiverIds.builder().build()).build());

        erpPutRequest.setReqData(ReqData.builder().data("我爱北京天安门！").build());
        AddInfos.AddInfo gavinZhang = AddInfos.AddInfo.builder().name("gavinZhang").value("张均富").build();
        erpPutRequest.setAddInfos(new AddInfos(Arrays.asList(gavinZhang)));

        System.out.println(JsonUtil.toJsonString(erpPutRequest));

    }
}
